const app=getApp()
const userDB=wx.cloud.database().collection("user")
const recordsDB=wx.cloud.database().collection("records")

var o = [ {
  img: "https://tenfei05.cfp.cn/creative/vcg/800/new/VCG211284671336.jpg",
  name: "鸟鸣",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/Bird.wav",
  type: "助眠"
}, {
  img: "https://tenfei04.cfp.cn/creative/vcg/800/version23/VCG41508476483.jpg",
  name: "雷声",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/thunder1.mp3",
  type: "减压"
}, {
  img: "https://alifei03.cfp.cn/creative/vcg/veer/800/new/VCG41N697259596.jpg",
  name: "雨滴",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/Rain.aac",
  type: "减压"
}, {
  img: "https://tenfei04.cfp.cn/creative/vcg/800/new/VCG41165593347.jpg",
  name: "流水",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/brook1.mp3",
  type: "助眠"
}, {
  img: "https://alifei04.cfp.cn/creative/vcg/800/new/VCG21gic20016408.jpg",
  name: "山林",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/summer_hill2.mp3",
  type: "减压"
}, {
  img: "https://alifei04.cfp.cn/creative/vcg/veer/800/new/VCG41N907642998.jpg",
  name: "海岸",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/summer_beach1.mp3",
  type: "助眠"
},
{
  img: "https://alifei05.cfp.cn/creative/vcg/800/new/VCG211231093573.jpg",
  name: "微波",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/small_wave.mp3",
  type: "助眠"
},  {
  img: "https://alifei01.cfp.cn/creative/vcg/800/new/VCG211336163779.jpg",
  name: "风",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/wind.mp3",
  type: "助眠"
},  {
  img: "https://alifei03.cfp.cn/creative/vcg/800/new/VCG41N802793600.jpg",
  name: "流落",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/duster.mp3",
  type: "减压"
},
{
  img: "https://alifei02.cfp.cn/creative/vcg/800/new/VCG211292416286.png",
  name: "风铃",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/door_bell.mp3",
  type: "减压"
}, {
  img: "https://tenfei05.cfp.cn/creative/vcg/800/new/VCG41165792378.jpg",
  name: "沐浴",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/in_a_bath.mp3",
  type: "减压"
}, {
  img: "https://alifei02.cfp.cn/creative/vcg/800/new/VCG211249401130.jpg",
  name: "风雪行",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/walking_in_snowstorm.mp3",
  type: "减压"
}, {
  img: "https://tenfei01.cfp.cn/creative/vcg/veer/800/new/VCG41N680381084.jpg",
  name: "秋天街头",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/walking_on_a_fall_street.mp3",
  type: "减压"
}, 
{
  img: "https://alifei01.cfp.cn/creative/vcg/veer/800/new/VCG41N862201756.jpg",
  name: "滴落",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/waterdrops.mp3",
  type: "减压"
}, {
  img: "https://alifei03.cfp.cn/creative/vcg/800/new/VCG211386445886.jpg",
  name: "优美",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/lightMusic4.wav",
  type: "助眠"
}, {
  img: "https://tenfei01.cfp.cn/creative/vcg/800/new/VCG211267978381.jpg",
  name: "温柔",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/lightMusic5.wav",
  type: "助眠"
}, {
  img: "https://alifei03.cfp.cn/creative/vcg/800/new/VCG211278982939.jpg",
  name: "静谧",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/lightMusic6.wav",
  type: "助眠"
}, {
  img: "https://tenfei05.cfp.cn/creative/vcg/800/new/VCG211236192714.png",
  name: "空灵",
  src: "cloud://xiaotiao-6gcr9hxy3d8aa90f.7869-xiaotiao-6gcr9hxy3d8aa90f-1309378747/助眠减压/音乐/lightMusic7.wav",
  type: "助眠"
} ],

a = wx.createInnerAudioContext();
a.autoplay = true


Page({
    data: {          
        tabs: [ "减压", "助眠" ],
        current: 0,         
        isPlay: !1,
        dataList: [],
    },
     
  
 
  onLoad: function(a) {  
     this.initData()
  },
   
   
  tabSelect: function(a) {
    var e = [], c = a.currentTarget.dataset.id;
 
    if (0 == c) for (var p = 0; p < o.length; p++) "减压" == o[p].type && e.push(o[p]);
    if (1 == c) for (p = 0; p < o.length; p++) "助眠" == o[p].type && e.push(o[p]);
    this.setData({
      current: c,
      dataList: e
    });
  },
  initData:function(){
    var c=0
    var e = []
    for (var p = 0; p < o.length; p++) "减压" == o[p].type && e.push(o[p]);
    this.setData({
      current: c,
      dataList: e
    });
  },
  stop: function() {
      a.stop(), this.setData({
          isPlay: !1
      }), console.log("音乐已经停止播放");
  },
  click: function(o) {
      var t = o.currentTarget.dataset.id, e = this.data.dataList[t];
      a.src = e.src, 
      a.loop = !0, 
      a.play(), 
      this.setData({
          isPlay: !0
      }), console.log("开始播放音乐索引为：" + t);
  },

  onReady: function() {},

  audioPlay: function(o) {
    // var t = o.currentTarget.dataset.id, e = this.data.dataList[t];
    //   a.src = e.src, 
    //   a.loop = !0, 
      a.play();
 
  },
  audioPause: function() {
      a.pause();
  },
  audio14: function() {
      a.seek(14);
  },
  audioStart: function() {
      a.seek(0);
  },
  onShow: function(o) { 
    
  },
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {
        this.refreshtestdata();
  },
  onReachBottom: function() {},
  onShareAppMessage: function() {
        
  }
});